package net.wang.staffing_system.controller;


import net.wang.staffing_system.domain.response.ResponseError;
import org.hibernate.HibernateException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.sql.SQLException;

/**
 *
 */
@RestController
@ControllerAdvice
public class ExceptionHandleController {

    @ExceptionHandler(value = Exception.class)
    public ResponseError exceptionHandler(Exception e) {
        return new ResponseError(500, "全局异常", e.getMessage());
    }

    @ExceptionHandler(value = RuntimeException.class)
    public ResponseError runtimeExceptionHandler(Exception e) {
        return new ResponseError(501, "运行时异常", e.getMessage());
    }

    @ExceptionHandler(value = {HibernateException.class, SQLException.class})
    public ResponseError SQLExceptionHandler(Exception e) {
        return new ResponseError(502, "数据查询异常", e.getMessage());
    }

    @ExceptionHandler(value = IOException.class)
    public ResponseError IOExceptionHandler(IOException e) {
        return new ResponseError(503, "文件处理异常", e.getMessage());
    }

   /* @ExceptionHandler(value = NullPointerException.class)
    public ResponseError NullPointerExceptionHandler(NullPointerException e) {
        return new ResponseError(503, "服务器异常", e.getMessage());
    }

    @ExceptionHandler(value = NullPointerException.class)
    public ResponseError URLExceptionHandler(MalformedURLException e) {
        return new ResponseError(504, "请求异常", e.getMessage());
    }*/

}
